package com.aiyige.im.dialog;


import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.aiyige.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;


public class HistoryActionBottomDialog extends DialogFragment {
    @BindView(R.id.searchBtn)
    TextView searchBtn;
    @BindView(R.id.cleanBtn)
    TextView cleanBtn;
    Unbinder unbinder;
    Listener listener = null;

    public HistoryActionBottomDialog() {
    }

    public Listener getListener() {
        return listener;
    }

    public void setListener(Listener listener) {
        this.listener = listener;
    }


    public static HistoryActionBottomDialog newInstance() {
        HistoryActionBottomDialog fragment = new HistoryActionBottomDialog();
        fragment.setStyle(STYLE_NORMAL, R.style.BottomDialogTheme);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.history_action_bottom_dialog, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        Window window = getDialog().getWindow();
        if (window != null) {
            window.setGravity(Gravity.BOTTOM);
            window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    @OnClick({R.id.searchBtn, R.id.cleanBtn,R.id.cancelBtn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.searchBtn:
                if (listener != null) {
                    listener.onClickSearch();
                }
                break;
            case R.id.cleanBtn:
                if (listener != null) {
                    listener.onClickClean();
                }
                break;
            case R.id.cancelBtn:
                dismiss();
                return;
        }


        dismiss();
    }

    public interface Listener {
        void onClickSearch();
        void onClickClean();
    }
}
